home *** CD-ROM | disk | FTP | other *** search
/ CyberMycha 2008 January / Cybermycha 1_2008.iso / Data.cab / _F87952DFBFC3461C9EF5579134A9FFA2 < prev    next >
Encoding:
Text File  |  2004-07-22  |  2.8 KB  |  88 lines

  1.  
  2. regc( 0, "TFACTOR" )
  3. regc4f( 3, %dirtcolor_r, %dirtcolor_g, %dirtcolor_b, %sunvisibility )
  4. regc4f( 4, %dirtsnow, %dirtgravel, %dirtmud, 0.0 )
  5. regc4f( 5, %daycolor_r, %daycolor_g, %daycolor_b, %daycolor_a )
  6. regc4f( 7, %ambient_r, %ambient_g, %ambient_b, %ambient_a )
  7.  
  8. hlsl("
  9. #include <../common_hlsl.h>
  10. #include <cardef.h>
  11.  
  12. sampler2D    sColor: register(s0);     
  13. sampler2D    sDirt: register(s1);    
  14. sampler2D    sClouds: register(s2);
  15. sampler2D    sLightmap: register(s3);
  16. samplerCUBE    sCubemap: register(s4);
  17. sampler2D    sDirtNormalmap: register(s5);
  18.  
  19. const HALF4 DirtLevel : register(c0); // DirtLevel.a 
  20. const HALF4 DirtColor_Sun : register(c3);
  21. const HALF3 DirtType : register(c4);
  22. const HALF3 DayColor : register(c5);
  23. const HALF4 Ambient : register(c7);
  24.  
  25. static const HALF3 Tiling = {SNOWTILING, GRAVELTILING, MUDTILING};
  26. static const HALF3 FlatNormal = {0.0f, 0.0f, 1.0f};
  27.  
  28. struct PS_INPUT
  29. {
  30.     HALF        SpotDiffuse: COLOR0;
  31.     HALF2       uvColor : TEXCOORD0;
  32.     float3      L : TEXCOORD1;
  33.     float3      R_ts : TEXCOORD2;
  34.     float3         R_ws: TEXCOORD3;
  35.     HALF2        Fresnel_and_Weight: TEXCOORD4;
  36.     HALF2       uvClouds: TEXCOORD5;
  37.     HALF2       uvLightmap: TEXCOORD6;
  38. };    
  39.     
  40. HALF4 main( PS_INPUT i ): COLOR {
  41.  
  42.     HALF Fresnel = i.Fresnel_and_Weight.x;
  43.     HALF DamageLevel = i.Fresnel_and_Weight.y;
  44.     HALF4 DirtScratch = tex2D( sDirt, i.uvColor );
  45.     HALF Scratch = DirtScratch.a*DamageLevel;
  46.     HALF3 DirtColor = DirtColor_Sun.rgb;
  47.     HALF SunVisibility = DirtColor_Sun.a;    
  48.  
  49.     HALF DirtMask = saturate(dot(DirtScratch.rgb, DirtType)*DirtLevel.a - Scratch);
  50.     HALF3 DirtNormalmapTiling = dot(DirtType, Tiling);
  51.     HALF3 Normalmap = tex2D( sDirtNormalmap, i.uvColor*DirtNormalmapTiling )*2 - 1;
  52.     Normalmap = lerp( FlatNormal, Normalmap, DirtMask);
  53.     HALF Diffuse = diffuse( Normalmap, i.L);
  54.     HALF Specular = phong(i.R_ts, i.L, SPECULARPOW)*SunVisibility;
  55.     HALF3 Cubemap    = texCUBE( sCubemap, i.R_ws);
  56.     
  57.     HALF Clouds = 1-(tex2D(sClouds, i.uvClouds)).a;
  58.     HALF Lightmap = saturate((tex2D(sLightmap, i.uvLightmap)).a);
  59.     HALF Shadows = saturate(Clouds*Lightmap*SHADOWSMUL+SOFTSHADOWS);
  60.  
  61.     Diffuse = saturate(Ambient.r*Shadows*Diffuse + Ambient.a);
  62.  
  63.     HALF4 Color = tex2D( sColor, i.uvColor );
  64.  
  65.     HALF CubemapMask = saturate(Color.a*2-1);
  66.     HALF SpecularMask = saturate(Color.a*2);
  67.     CubemapMask = saturate(CubemapMask+Fresnel*CubemapMask*16-Scratch);    
  68.     CubemapMask *= 1-DirtMask;
  69.     SpecularMask *=(1-DirtMask)*Shadows;
  70.     
  71.     Color.rgb = lerp( Color, DirtColor, DirtMask);
  72.     Color.rgb = lerp( Color, SCRATCHCOLOR, Scratch);
  73.  
  74. #if VS_SPOTLIGHTS
  75.     HALF3 Spot = Color.rgb*i.SpotDiffuse;
  76. #endif    
  77.  
  78.     Color.rgb = saturate(Color*Diffuse+Specular*SpecularMask+Cubemap*CubemapMask)*DayColor;
  79.  
  80. #if VS_SPOTLIGHTS
  81.     Color.rgb = saturate(Color+Spot);
  82. #endif    
  83.     Color.a = WATERDEEP;  // water
  84.     return Color;
  85. }
  86. ")
  87.  
  88.